package com.sky.utils;

import lombok.Data;
import org.apache.http.HttpStatus;

import java.io.Serializable;

/**
 * 返回数据
 *
 * @author Mark sunlightcs@gmail.com
 */
@Data
public class R<T> implements Serializable {
	private static final long serialVersionUID = 1L;

	private T data;
	private int code = 0;
	private String msg = "success";

	public R() {
	}

	public R(T data) {
		this.data = data;
	}

	public R(int code, String msg) {
		this.code = code;
		this.msg = msg;
	}

	public R(int code, String msg, T data) {
		this.code = code;
		this.msg = msg;
		this.data = data;
	}

	public static R ok() {
		return new R();
	}
	public static <T> R ok(T data) {
		return new R(data);
	}

	public static R error() {
		return error(HttpStatus.SC_INTERNAL_SERVER_ERROR, "未知异常，请联系管理员");
	}

	public static R error(String msg) {
		return error(HttpStatus.SC_INTERNAL_SERVER_ERROR, msg);
	}

	public static R error(String msg,Object object) {
		return error(HttpStatus.SC_INTERNAL_SERVER_ERROR, msg, object);
	}

	public static R error(int code, String msg) {
		return new R(code,msg);
	}

	public static <T> R error(int code, String msg, T data) {
		return new R(code,msg,data);
	}
}
